<?php
namespace Admin\Model;

use Think\Model;

class MessageModel extends Model {
    
    const TYPE_SHIPPING = 1;
    const TYPE_ORDER = 2;
    const TYPE_NOTICE = 3;
    const TYPE_TIMING = 4;
    const TYPE_EVENT = 5;
    const TYPE_SHIPPING_TEXT = '物流消息';
    const TYPE_ORDER_TEXT = '交易消息';
    const TYPE_NOTICE_TEXT = '通知消息';
    const TYPE_TIMING_TEXT = '定时消息';
    const TYPE_EVENT_TEXT = '趣那活动';
    
    protected $_auto = array (
        array('is_read', 0, self::MODEL_INSERT),
        array('read_time', 0, self::MODEL_INSERT),
        array('create_time', NOW_TIME, self::MODEL_INSERT)
    );
    
    public function quickMessage($uid, $type, $message, $image = '') {
        switch ($type) {
            case self::TYPE_SHIPPING:
                $data['title'] = self::TYPE_SHIPPING_TEXT;
                break;
            case self::TYPE_ORDER:
                $data['title'] = self::TYPE_ORDER_TEXT;
                break;
            case self::TYPE_NOTICE:
                $data['title'] = self::TYPE_NOTICE_TEXT;
                break;
            case self::TYPE_TIMING:
                $data['title'] = self::TYPE_TIMING_TEXT;
                break;
            case self::TYPE_EVENT:
                $data['title'] = self::TYPE_EVENT_TEXT;
                break;
            default:
                return false;
                break;
        }
        $data['uid'] = $uid;
        $data['type'] = $type;
        $data['message'] = $message;
        $data['image'] = $image;
        $data = $this->create($data);
        $res = $this->add();
        return $res;
    }
    
}